package com.qf.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.dao.CustomerDao;
import com.qf.entity.Customer;
import com.qf.service.CustomerService;
import com.qf.vo.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class customerServiceImpl implements CustomerService {
    @Autowired
    private CustomerDao customerDao;

//    @Override
//    @Transactional(propagation = Propagation.SUPPORTS)
//    public PageInfo<Customer> findAll(PageVo pageVo) {
//        PageHelper.startPage(pageVo.getPage(),pageVo.getLimit());
//        List<Customer> Customers=customerDao.findAllCustomer();
//        System.out.println(Customers);
//
//       return new PageInfo<Customer>(Customers);
//
//
//    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS)
    public PageInfo<Customer> findAll(PageVo pageVo, Customer customer) {
       PageHelper.startPage(pageVo.getPage(),pageVo.getLimit());
       List<Customer> customers=customerDao.findAllByCondition(customer);
       return new PageInfo<>(customers);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertCustomer(Customer customer) {
        return customerDao.insertCustomer(customer);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer deleteUser(Integer[] ids) {
        return customerDao.deleteCustomers(ids);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer updateCustomer(Customer customer) {
        return customerDao.update(customer);
    }
}
